In [1]:
import data
import pandas as pd
In [2]:
mydata = data.alldata.copy()
mydata
Out[2]:
mains
television
fan
fridge
laptop computer
electric heating element
oven
unknown
washing machine
microwave
toaster
sockets
cooker
Kitchen
LivingRoom
StoreRoom
Room1
Room2
2015-07-05 00:00:03
0.0
0.0
0.00
0.000000
0.000000
0.00
0.0
0.0
0.00
0.00
0.0
0.00
0.0
1
0
0
0
0
2015-07-05 00:00:04
0.0
0.0
0.00
0.000000
0.000000
0.00
0.0
0.0
0.00
0.00
0.0
0.00
0.0
0
0
0
0
0
2015-07-05 00:00:05
0.0
0.0
0.00
0.000000
0.000000
0.00
0.0
0.0
0.00
0.00
0.0
0.00
0.0
0
0
0
0
0
2015-07-05 00:00:06
0.0
0.0
0.00
0.000000
0.000000
0.00
0.0
0.0
0.00
0.00
0.0
0.00
0.0
0
0
0
0
0
2015-07-05 00:00:07
0.0
0.0
0.00
0.000000
0.000000
0.00
0.0
0.0
0.00
0.00
0.0
7.35
0.0
0
1
0
0
0
2015-07-05 00:00:08
223.0
0.0
0.00
99.210000
0.000000
0.00
0.0
0.0
0.00
0.00
0.0
7.35
0.0
0
0
1
0
1
2015-07-05 00:00:09
223.6
0.0
0.00
99.179070
28.340000
0.00
0.0
0.0
0.00
0.00
0.0
7.35
0.0
0
1
0
0
0
2015-07-05 00:00:10
224.2
0.0
0.00
99.148140
28.378095
0.00
0.0
0.0
0.00
0.00
0.0
7.35
0.0
0
1
0
0
0
2015-07-05 00:00:11
224.8
0.0
0.00
99.117209
28.416190
2.29
0.0
0.0
0.00
0.00
0.0
7.35
0.0
1
0
0
0
0
2015-07-05 00:00:12
225.4
0.0
0.00
99.086279
28.454286
2.29
0.0
0.0
0.00
0.00
0.0
7.35
0.0
0
0
0
0
0
2015-07-05 00:00:13
226.0
0.0
0.00
99.055349
28.492381
2.29
0.0
0.0
0.00
0.00
0.0
7.35
0.0
0
0
0
0
0
2015-07-05 00:00:14
226.6
0.0
0.00
99.024419
28.530476
2.29
0.0
0.0
0.00
0.00
0.0
7.35
0.0
0
0
0
0
0
2015-07-05 00:00:15
227.2
0.0
0.00
98.993488
28.568571
2.29
0.0
0.0
0.00
0.00
0.0
7.35
0.0
0
0
0
0
0
2015-07-05 00:00:16
227.8
0.0
0.00
98.962558
28.606667
2.29
0.0
0.0
0.00
0.00
0.0
7.35
0.0
0
0
0
0
0
2015-07-05 00:00:17
228.4
0.0
0.00
98.931628
28.644762
2.29
0.0
0.0
0.00
0.00
0.0
7.35
0.0
0
0
0
0
0
2015-07-05 00:00:18
229.0
0.0
0.00
98.900698
28.682857
2.29
0.0
0.0
0.00
0.00
0.0
7.35
0.0
0
0
0
0
0
2015-07-05 00:00:19
226.1
0.0
0.00
98.869767
28.720952
2.29
0.0
0.0
0.00
0.00
0.0
7.35
0.0
0
0
0
0
0
2015-07-05 00:00:20
223.2
0.0
0.00
98.838837
28.759048
2.29
0.0
0.0
0.00
0.00
0.0
7.35
0.0
0
0
0
0
0
2015-07-05 00:00:21
220.3
0.0
0.00
98.807907
28.797143
2.29
0.0
0.0
0.00
0.00
0.0
7.35
0.0
0
0
0
0
0
2015-07-05 00:00:22
217.4
0.0
29.65
98.776977
28.835238
2.29
0.0
0.0
0.00
1.24
0.0
7.35
0.0
0
0
1
1
0
2015-07-05 00:00:23
214.5
0.0
29.65
98.746047
28.873333
2.29
0.0
0.0
0.00
1.24
0.0
7.35
0.0
0
0
0
0
0
2015-07-05 00:00:24
211.6
0.0
29.65
98.715116
28.911429
2.29
0.0
0.0
0.00
1.24
0.0
7.35
0.0
0
0
0
0
0
2015-07-05 00:00:25
208.7
0.0
29.65
98.684186
28.949524
2.29
0.0
0.0
0.00
1.24
0.0
7.35
0.0
1
0
0
0
0
2015-07-05 00:00:26
205.8
0.0
29.65
98.653256
28.987619
2.29
0.0
0.0
0.68
1.24
0.0
7.35
0.0
1
0
0
0
0
2015-07-05 00:00:27
202.9
0.0
29.65
98.622326
29.025714
2.29
0.0
0.0
0.68
1.24
0.0
7.35
0.0
0
0
0
0
0
2015-07-05 00:00:28
200.0
0.0
29.65
98.591395
29.063810
2.29
0.0
0.0
0.68
1.24
0.0
7.35
0.0
0
0
0
0
0
2015-07-05 00:00:29
199.9
0.0
29.65
98.560465
29.101905
2.29
0.0
0.0
0.68
1.24
0.0
7.35
0.0
0
0
0
0
0
2015-07-05 00:00:30
199.8
0.0
29.65
98.529535
29.140000
2.29
0.0
0.0
0.68
1.24
0.0
7.35
0.0
0
0
0
0
0
2015-07-05 00:00:31
199.7
0.0
29.65
98.498605
29.178095
2.29
0.0
0.0
0.68
1.24
0.0
7.35
0.0
0
0
0
0
0
2015-07-05 00:00:32
199.6
0.0
29.65
98.467674
29.216190
2.29
0.0
0.0
0.68
1.24
0.0
7.35
0.0
0
0
0
0
0
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
2015-12-05 21:54:46
0.0
0.0
0.00
0.000000
17.400000
2.55
0.0
0.0
0.95
1.24
0.0
1.39
0.0
0
0
0
0
0
2015-12-05 21:54:47
0.0
0.0
0.00
0.000000
17.400000
2.55
0.0
0.0
0.95
1.24
0.0
1.39
0.0
0
0
0
0
0
2015-12-05 21:54:48
0.0
0.0
0.00
0.000000
17.400000
2.55
0.0
0.0
0.95
1.24
0.0
1.39
0.0
0
0
0
0
0
2015-12-05 21:54:49
0.0
0.0
0.00
0.000000
17.400000
2.55
0.0
0.0
0.95
1.24
0.0
1.39
0.0
0
0
0
0
0
2015-12-05 21:54:50
0.0
0.0
0.00
0.000000
17.400000
2.55
0.0
0.0
0.95
1.24
0.0
1.39
0.0
0
0
0
0
0
2015-12-05 21:54:51
0.0
0.0
0.00
0.000000
17.400000
2.55
0.0
0.0
0.95
1.24
0.0
1.39
0.0
0
0
0
0
0
2015-12-05 21:54:52
0.0
0.0
0.00
0.000000
17.400000
2.55
0.0
0.0
0.95
1.24
0.0
1.39
0.0
0
0
0
0
0
2015-12-05 21:54:53
0.0
0.0
0.00
0.000000
17.400000
2.55
0.0
0.0
0.95
1.24
0.0
1.39
0.0
0
0
0
0
0
2015-12-05 21:54:54
0.0
0.0
0.00
0.000000
17.400000
2.55
0.0
0.0
0.95
1.24
0.0
1.39
0.0
0
0
0
0
0
2015-12-05 21:54:55
0.0
0.0
0.00
0.000000
17.400000
2.55
0.0
0.0
0.95
1.24
0.0
1.39
0.0
0
0
0
0
0
2015-12-05 21:54:56
0.0
0.0
0.00
0.000000
17.400000
2.55
0.0
0.0
0.95
1.24
0.0
1.39
0.0
0
0
0
0
0
2015-12-05 21:54:57
0.0
0.0
0.00
0.000000
17.400000
2.55
0.0
0.0
0.95
1.24
0.0
1.39
0.0
0
0
0
0
0
2015-12-05 21:54:58
0.0
0.0
0.00
0.000000
17.400000
2.55
0.0
0.0
0.95
1.24
0.0
1.39
0.0
0
0
0
0
0
2015-12-05 21:54:59
0.0
0.0
0.00
0.000000
17.400000
2.55
0.0
0.0
0.95
1.24
0.0
1.39
0.0
0
0
0
0
0
2015-12-05 21:55:00
0.0
0.0
0.00
0.000000
17.400000
2.55
0.0
0.0
0.95
1.24
0.0
1.39
0.0
0
0
0
0
0
2015-12-05 21:55:01
0.0
0.0
0.00
0.000000
17.400000
2.55
0.0
0.0
0.95
1.24
0.0
1.39
0.0
0
0
0
0
0
2015-12-05 21:55:02
0.0
0.0
0.00
0.000000
17.400000
2.55
0.0
0.0
0.95
1.24
0.0
1.39
0.0
0
0
0
0
0
2015-12-05 21:55:03
0.0
0.0
0.00
0.000000
17.400000
2.55
0.0
0.0
0.95
1.24
0.0
1.39
0.0
0
0
0
0
0
2015-12-05 21:55:04
0.0
0.0
0.00
0.000000
17.400000
2.55
0.0
0.0
0.95
1.24
0.0
1.39
0.0
0
0
0
0
0
2015-12-05 21:55:05
0.0
0.0
0.00
0.000000
16.675000
2.55
0.0
0.0
0.95
1.24
0.0
1.39
0.0
0
0
0
0
0
2015-12-05 21:55:06
0.0
0.0
0.00
0.000000
15.950000
2.55
0.0
0.0
0.95
1.24
0.0
1.39
0.0
0
0
0
0
0
2015-12-05 21:55:07
0.0
0.0
0.00
0.000000
15.225000
2.55
0.0
0.0
0.95
1.24
0.0
1.39
0.0
0
0
0
0
0
2015-12-05 21:55:08
0.0
0.0
0.00
0.000000
14.500000
2.55
0.0
0.0
0.95
1.24
0.0
1.39
0.0
0
0
0
0
0
2015-12-05 21:55:09
0.0
0.0
0.00
0.000000
13.775000
2.55
0.0
0.0
0.95
1.24
0.0
1.39
0.0
0
0
0
0
0
2015-12-05 21:55:10
0.0
0.0
0.00
0.000000
13.050000
2.55
0.0
0.0
0.95
1.24
0.0
1.39
0.0
0
0
0
0
0
2015-12-05 21:55:11
0.0
0.0
0.00
0.000000
12.325000
2.55
0.0
0.0
0.95
1.24
0.0
1.39
0.0
0
0
0
0
0
2015-12-05 21:55:12
0.0
0.0
0.00
0.000000
11.600000
2.55
0.0
0.0
0.95
1.24
0.0
1.39
0.0
0
0
0
0
0
2015-12-05 21:55:13
0.0
0.0
0.00
0.000000
10.875000
2.55
0.0
0.0
0.95
1.24
0.0
1.39
0.0
0
0
0
0
0
2015-12-05 21:55:14
0.0
0.0
0.00
0.000000
10.150000
2.55
0.0
0.0
0.95
1.24
0.0
1.39
0.0
0
0
0
0
0
2015-12-05 21:55:15
0.0
0.0
0.00
0.000000
9.425000
2.55
0.0
0.0
0.95
1.24
0.0
1.39
0.0
0
1
0
0
0
13298113 rows × 18 columns
In [7]:
from sklearn import tree
import matplotlib.pyplot as plt
import datetime as dt
import numpy as np
mydata1 = mydata.copy()
x3 = mydata1[['television','fan','fridge','laptop computer','electric heating element','oven','unknown','washing machine','microwave','toaster','sockets','cooker']]
#xrange = np.arange(x3.min(),x3.max(),(x3.max()-x3.min())/100).reshape(100,1)
y1 = mydata1['Kitchen'].astype(float)
y2 = mydata1['LivingRoom'].astype(float)
y3 = mydata1['StoreRoom'].astype(float)
y4 = mydata1['Room1'].astype(float)
y5 = mydata1['Room2'].astype(float)
In [11]:
reg1 = tree.DecisionTreeClassifier(max_depth=10)
reg1.fit(x3,y1)
reg1.score(x3,y1)
Out[11]:
0.99987110953260816
In [12]:
reg2 = tree.DecisionTreeClassifier(max_depth=10)
reg2.fit(x3,y2)
reg2.score(x3,y2)
Out[12]:
0.999727028940121
In [13]:
reg3 = tree.DecisionTreeClassifier(max_depth=10)
reg3.fit(x3,y3)
reg3.score(x3,y3)
Out[13]:
0.99995608399477431
In [14]:
reg4 = tree.DecisionTreeClassifier(max_depth=10)
reg4.fit(x3,y4)
reg4.score(x3,y4)
Out[14]:
0.999986765039521
In [15]:
reg5 = tree.DecisionTreeClassifier(max_depth=10)
reg5.fit(x3,y5)
reg3.score(x3,y5)
Out[15]:
0.99993645714997303
Content source: marioberges/F16-12-752
Similar notebooks: